#include <iostream>
#include <cstring>
using namespace std;
const int N = 1010;
using LL = long long;
LL dp[N][N];

LL n, k;


int main() {
    cin >> n >> k;
    memset(dp, -1, sizeof dp);
    dp[0][0] = 0;
    for(int i = 1; i <= n; ++i)
    {
        LL tmp;
        cin >> tmp;
        for(LL j = 0; j < k; ++j)
        {
            int tt = (((j - tmp) % k) + k) % k;
            // cout << tt << ' ';
            dp[i][j] = dp[i - 1][j];
            if(dp[i - 1][tt] != -1)
                dp[i][j] = max(dp[i][j], dp[i - 1][tt] + tmp);
        }
        // cout << endl;
    }
    if(dp[n][0] == 0) cout << -1 << endl;
    else cout << dp[n][0] << endl;
    return 0;

}
// 64 位输出请用 printf("%lld")